home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 13140 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.8 KB  |  52 lines

  1. Path: sun001.spd.dsccc.com!jmccarty
  2. From: jmccarty@sun1307.spd.dsccc.com (Mike McCarty)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Opening STDOUT As BINARY
  5. Date: 4 Apr 1996 22:16:46 GMT
  6. Organization: DSC Communications Corporation
  7. Message-ID: <4k1hoe$hn0@sun001.spd.dsccc.com>
  8. References: <3161CAD8.296C@netrover.com>
  9. NNTP-Posting-Host: sun1307.spd.dsccc.com
  10.  
  11. In article <3161CAD8.296C@netrover.com>,
  12. Stephane Charette  <charrick@netrover.com> wrote:
  13. )I've come across a problem, and I believe that it is
  14. )caused by limitations in C/C++.  Can anyone help on the
  15. )following:
  16. )
  17. )I need to output binary information to the console, which
  18. )is then redirected to a file by the o/s.  At the moment,
  19. )I'm using printf( "%c", mychar ) to output the the binary
  20. )data one character at a time as it comes in.
  21. )
  22. )However, it seems that the character #7 (0x07, bell) gets
  23. )sent to stdout followed by an automatic CR (0x0A).  Every
  24. )other character in the ASCII table works fine!  Is there
  25. )a way to reopen stdout in binary mode instead of as a text
  26. )stream? The extra 0x0A characters are corrupting the data!
  27. )
  28. )I've also tried "cout" and "putc", but they yield the same
  29. )result.
  30. )
  31. )Why do I need this:  this application runs as a CGI-BIN,
  32. )and the web server EXPECTS the output to be sent to
  33. )stdout.  I cannot fwrite() this information to a physical
  34. )file since the web server is capturing the console output!
  35. )
  36. )Thanks for any help,
  37. )
  38. )Stephane Charette.
  39.  
  40.  
  41. The behavior you describe has -nothing- to do with C. It has to do with
  42. the peculiarities of the operating system you are using. Is htis DOS? If
  43. so, then investigate putting stdout in binary mode. Your compiler should
  44. have a way to do this. Look into variables such as _fmode, __mode etc.
  45.  
  46. Mike
  47. -- 
  48. ----
  49. char *p="char *p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);}
  50.  
  51. I don't speak for DSC.         <- They make me say that.
  52.